let prices = [7,1,5,3,6,4]

var maxProfit = function(prices) {
    let len = prices.length;
    let maxPrice = [len]
    let Profit = [len]
    for(let i = 0; i < len; i++) {
        Profit[i] = max(prices, i) - prices[i]
    }
    let maxProfit = max(Profit,0)
    return maxProfit;
};

var max = function(price,i) {
    let len = price.length
    let max = price[i];
    for (;i<len;i++) {
        if(price[i] > max){
            max = price[i];
        }
    }
    return max;
}